<?php
/**
 * 实用类
 *
 * @author 孙晓晔
 * @version $Id: Util.class.php 421 2009-10-28 07:31:09Z sunxy $
 */
class Util {
	var $version;		// 软件版本
	var $update;		// 更新时间

	var $dsn;				// 定义数据源
	var $pagesize;			// 定义分页大小

	var $db;				// 定义数据库
	var $i = 0;
	var $result = array();  // 定义计算结果	

	var $tbl;

	function __construct($request) {
		global $cfg;

		$this->dsn = 'root';
		$this->pagesize = (empty($_REQUEST['pagesize_s']) ? 15 : $_REQUEST['pagesize_s']);

		$d = preg_split("/[\s,|\$]+/", $request['update']);
		$t = strtotime($d[2] . ' ' . $d[3]);

		$r = preg_split("/[\s,|\$]+/", $request['revision']);

		$this->version = $r[2];
		$this->update = date('Y-m-d H:i:s', $t + 28800);
	}

	

	function totaltime($request) {
		$starttime = $request['starttime'];

		$mtime = explode(" ", microtime());
		$endtime = $mtime[1] + $mtime[0];
		$totaltime = $endtime - $starttime;

		return number_format($totaltime, 7);
	}
		
	function doGet(&$request, $method) {
		$command = $request['do'];
		$commandArray = explode('.', $command);

		return '?do=' . $commandArray[0] . "." . $method;
	}

	function f($row) {
		if (empty($row)) {
			return '';
		}
		
		$s = '';
		foreach ($row as $k => $v) {
			$s .= $k . "=" . $v ."&";
		}

		return trim($s, '&');
	}

	function id($tbl, $id) {
		return Common::id($tbl, $id);
	}

	function code($tbl, $code) {
		return Common::code($tbl, $code);
	}

	function name($tbl, $name) {
		return Common::name($tbl, $name);
	}

	function id_option($tbl, $status = '1') {
		return Common::id_option($tbl, $status);
	}

	function code_option($tbl, $status = '1') {
		return Common::code_option($tbl, $status);
	}

	function name_id($tbl, $id) {
		return Common::name_id($tbl, $id);
	}

	function name_code($tbl, $code) {
		return Common::name_code($tbl, $code);
	}

	function age($dd) {
		return Common::age($dd);
	}
}
?>